<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

include_once ('bd/ModeloBD.php');

class ModeloVehiculo extends ModeloBD {

    private $vehicodsx;
    private $tipovehicodsx;
    private $sucurcodsx;
    private $vehiplaca;
    private $vehimarca;
    private $vehimodelo;
    private $vehidisponible;
    private $vehiestado;

    public function __construct($vehicodsx = "", $tipovehicodsx = "", $sucurcodsx = "", $vehiplaca = "", $vehimarca = "", $vehimodelo = "", $vehidisponible = "", $vehiestado = "") {
        $this->_oBaseDatos = CBaseDatos::get_instancia();
        $this->_oBaseDatos->conectar();
        $this->_sTabla = "vehiculo";
        $this->vehicodsx = $vehicodsx;
        $this->tipovehicodsx = $tipovehicodsx;
        $this->sucurcodsx = $sucurcodsx;
        $this->vehiplaca = $vehiplaca;
        $this->vehimarca = $vehimarca;
        $this->vehimodelo = $vehimodelo;
        $this->vehidisponible = $vehidisponible;
        $this->vehiestado = $vehiestado;
    }

    //Ojo q falta la consulta
    public function listaVehiculos() {
        $arVehiculo = null;
        $tabla2 = "sucursal";
        $tabla3 = "tipovehiculo";
        $sSQL = "
          SELECT a.*, b.sucurnombre , c.tipovehinombre
          FROM $this->_sTabla a, $tabla2 b, $tabla3 c where a.sucurcodsx=b.sucurcodsx and a.tipovehicodsx=c.tipovehicodsx and vehiestado=1 
                  order by vehicodsx  desc ";
        $arVehiculo = $this->query_object($sSQL);
//          var_dump($sSQL);
        //        var_dump($arSucursal['usuario'][0]['usucodsx']); //QUERY
        //        var_dump($arSucursal[0]->usucodsx); //QUERY_OBJECT
        return $arVehiculo;
    }

    public function getVehiculoById($vehicodsx) {
        $arVehiculo = null;
        $sSQL = "
            SELECT *
            FROM $this->_sTabla   where vehicodsx=" . $vehicodsx;
        $arVehiculo = $this->query_object($sSQL);
//        var_dump($arSucursal['usuario'][0]['usucodsx']); //QUERY
//        var_dump($arSucursal[0]->usucodsx); //QUERY_OBJECT
        return $arVehiculo;
    }
    public function getVehiculoByTipoYSucursal($tipovehicodsx,$sucurcodsx) {
        $arVehiculo = null;
        $sSQL = "
            SELECT *
            FROM $this->_sTabla   where tipovehicodsx=" . $tipovehicodsx . " and sucurcodsx=" .$sucurcodsx . " and vehiestado =1 and vehidisponible=1";
        $arVehiculo = $this->query_object($sSQL);
//        var_dump($arSucursal['usuario'][0]['usucodsx']); //QUERY
//        var_dump($arSucursal[0]->usucodsx); //QUERY_OBJECT
        return $arVehiculo;
    }

    public function crearVehiculo() {
        $tipovehicodsx = $this->tipovehicodsx;
        $sucurcodsx = $this->sucurcodsx;
        $vehiplaca = $this->vehiplaca;
        $vehimodelo = $this->vehimodelo;
        $vehimarca = $this->vehimarca;
        $vehimodelo = $this->vehimodelo;
        $vehidisponible = $this->vehidisponible;
        $vehiestado = $this->vehiestado;

        $sSQL = "INSERT INTO $this->_sTabla
               (tipovehicodsx,  sucurcodsx, vehiplaca,vehimarca, vehimodelo,vehidisponible,vehiestado)
               VALUES('$tipovehicodsx','$sucurcodsx','$vehiplaca', '$vehimarca','$vehimodelo','$vehidisponible','$vehiestado')";
        $this->execute($sSQL);
    }

    public function actualizarVehiculo() {
        $vehicodsx = $this->vehicodsx;
        $tipovehicodsx = $this->tipovehicodsx;
        $sucurcodsx = $this->sucurcodsx;
        $vehiplaca = $this->vehiplaca;
        $vehimarca = $this->vehimarca;
        $vehimodelo = $this->vehimodelo;


        $sSQL = "UPDATE $this->_sTabla
               SET
               tipovehicodsx = '$tipovehicodsx',
               sucurcodsx = '$sucurcodsx',
               vehiplaca = '$vehiplaca',
               vehimarca = '$vehimarca',
               vehimodelo = '$vehimodelo'
               WHERE vehicodsx = $vehicodsx";

        $this->execute($sSQL);
    }

    public function actualizarEstado($vehicodsx, $vehiestado) {

        $sSQL = "UPDATE $this->_sTabla
               SET
               vehiestado = $vehiestado
               WHERE $vehicodsx = $vehicodsx";
        $this->execute($sSQL);
    }
    public function actualizarEstadoDisponible($vehicodsx, $vehidisponible) {

        $sSQL = "UPDATE $this->_sTabla
               SET
               vehidisponible = $vehidisponible
               WHERE $vehicodsx = $vehicodsx";
        $this->execute($sSQL);
    }
    public function actualizarSucursal($vehicodsx, $sucurcodsx) {

        $sSQL = "UPDATE $this->_sTabla
               SET
               sucurcodsx = $sucurcodsx
               WHERE $vehicodsx = $vehicodsx";
        $this->execute($sSQL);
    }

}

?>
